package com.tracy.life.utils;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * ***********************************************************
 * author: alex
 * time: 16/7/19 下午3:10
 * name:
 * overview:
 * usage:
 * *************************************************************
 */
public abstract class CommonAdapter<T> extends RecyclerView.Adapter<MyHolder> {
    private Context mContext;
    private List<T> mDatas;
    private int mItemLayoutId;

    public CommonAdapter(Context context, List<T> datas, int itemLayoutId) {
        this.mContext = context;
        this.mDatas = datas;
        this.mItemLayoutId = itemLayoutId;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(mItemLayoutId, parent, false);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        //模板设计模式。
        bindData(holder, position, mDatas.get(position));

    }

    @Override
    public int getItemCount() {
        return mDatas == null ? 0 : mDatas.size();
    }

    public abstract void bindData(MyHolder holder, int position, T bean);
}
